package com.zhangwei.moni_two.service;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhangwei.moni_two.dao.UserDao;
import com.zhangwei.moni_two.entity.User;



@Service
public class UserServiceImp implements UserService {

	@Autowired
	private UserDao dao;

	@Override
	public Integer selLoginName(User user, HttpSession session) {
		// TODO Auto-generated method stub
		//根据输入的登录名去数据库查询
		User user2 = dao.selLoginName(user.getLoginName());
		
		if(user2!=null){
			if(user.getPassword().equals(user2.getPassword())){
				//登陆成功
				session.setAttribute("login", user2);
				return 3;
			}else{
				//密码错误
				return 2;
			}
			
		}
		//用户名不存在
		return 1;
	}

	@Override
	public PageInfo<User> selAllUser(Integer pageNum, Integer pageSize) {
		// TODO Auto-generated method stub
		PageHelper.startPage(pageNum, pageSize);
		List<User> list = dao.selAllUser();
		return new PageInfo<User>(list);
	}

	@Override
	public Integer selAllCount() {
		// TODO Auto-generated method stub
		 Integer integer = dao.selAllCount();
		
		return integer;
	}

	@Override
	public Integer selByInformation(int i) {
		// TODO Auto-generated method stub
		return dao.selByInformation(i);
	}
}
